﻿#region Apache License
/* 
   Copyright 2011 Jorge Teixeira

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
#endregion

using System;

namespace AdHoc.Wavesque
{
    /// <summary>
    /// Helper methods.
    /// </summary>
    internal static class EsqueHelpers
    {
        /// <summary>
        /// Gets the value of the Nyquist rate.
        /// </summary>
        /// <remarks>
        /// The Nyquist rate is the minimum sampling rate required to avoid aliasing, equal to twice the highest 
        /// frequency contained within the signal.
        /// </remarks>
        /// <param name="frequency">The highest frequency contained within the signal.</param>
        /// <returns>The minimum sampling rate required to avoid aliasing, in samples per unit time.</returns>
        public static double NyquistRate(double frequency)
        {
            return 2.0 * frequency;
        }

        /// <summary>
        /// Gets the default value of the position increases.
        /// </summary>
        /// <param name="frequency">Frequency of the oscillation (in Hz).</param>
        /// <returns>A double, representing the value by which the position is increasead when calculating the value of the function.</returns>
        public static double GetStepDefaultValue(double frequency)
        {
            double samplingRate = NyquistRate(frequency);
            return 1.0 / (frequency * samplingRate);
        }

        /// <summary>
        /// Gets a default value for the number of points to generate.
        /// </summary>
        /// <param name="frequency">Frequency of the oscillation (in Hz).</param>
        /// <param name="step">Value of position increases.</param>
        /// <returns>A default value for the number of points to generate.</returns>
        public static uint GetNumberOfPointsDefault(double frequency, double step)
        {
            double period = 1 / frequency;
            double number = period / step;
            if (number < 0)
                return 0;
            return (uint)number;
        }
    }
}
